package org.pr.ddddesigner.infrastructure.support;

import ch.qos.logback.core.joran.node.ComponentNode;
import com.lion.commons.tools.scene.RenderType;
import com.xw.soonmanager.component.dto.BuildComponentRequestDto;
import com.xw.soonmanager.filemanager.ModelType;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import reactor.core.publisher.Mono;

import javax.xml.transform.Result;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;

import static com.xw.soonmanager.filemanager.ModelType.FBX;
import static com.xw.soonmanager.filemanager.ModelType.GLTF;

/**
 * @author chenbin
 */
@Component
public class SimpleComponentBuilder implements ComponentBuilder {
    private static final Set<ModelType> SUPPORTED_TYPES = new HashSet<>(Arrays.asList(GLTF, FBX));

    @Override
    public boolean support(ModelType type) {
        return SUPPORTED_TYPES.contains(type);
    }

    @Override
    public Mono<Result> build(BuildComponentRequestDto metadata) {
        return null;
    }

    /*@Transactional(rollbackFor = Exception.class, propagation = Propagation.NESTED)
    @Override
    public Mono<Result> build(BuildComponentRequestDto metadata) {
        return Mono.defer(() -> {
            ModelComponent component = ComponentBuilder.createComponent(metadata);
            Mono<ModelComponent> componentMono = component.save();

            ComponentEdition edition = ComponentBuilder.createEdition(metadata);
            edition.setComponentId(component.getId());
            Mono<ComponentEdition> editionMono = edition.save();

            ComponentNode node = ComponentBuilder.createNode(metadata);
            node.setComponentId(component.getId());
            node.setEditionId(edition.getId());
            node.setName(metadata.getName());
            node.setRenderType(RenderType._3D);
            if (metadata.getEntryList().size() > 0) {
                node.setLocation(metadata.getEntryList().get(0));
            }
            Mono<ComponentNode> nodeMono = node.save();

            Result result = new Result();
            result.setComponent(component);
            result.setEdition(edition);
            result.setNodes(Collections.singletonList(node));

            return Mono.when(componentMono, editionMono, nodeMono).thenReturn(result);
        });
    }*/
}
